<?php
	class n_ini{
	   public function w2i($values,$file,$section)
	   {
         $ini_file_array=parse_ini_file($file,1);

         if($section){
            foreach($values as $key => $value)
            {
               $keys=array_keys($value);
               for($i=0;$i<count($keys);$i++)
               {	
                  $ini_file_array[$key][$keys[$i]] = $values[$key][$keys[$i]];	
               }
               foreach($ini_file_array[$key] as $key2 => $value2)
               {
                  if($value2 ==" " || $value2==null){
                      $ini_file_array[$key][$key2] = "";

                  }
               }
            }
         }
         self::write_ini_file($ini_file_array, $file,$section);
	   }

	   private static function write_ini_file($assoc_arr, $path, $has_sections)
      {
         $content = '';
         if (!$handle = fopen($path, 'w'))
             return FALSE;

         self::_write_ini_file_r($content, $assoc_arr, $has_sections);
         if (!fwrite($handle, $content))
             return FALSE;
         fclose($handle);
         return TRUE;
      }

      private static function _write_ini_file_r(&$content, $assoc_arr, $has_sections)
      {
         foreach ($assoc_arr as $key => $val)
         {
             if (is_array($val))
             {
                 if($has_sections)
                 {
                     $content .= "[$key]\n";
                     self::_write_ini_file_r(&$content, $val, false);
                 }
                 else
                 {
                     foreach($val as $iKey => $iVal)
                     {
                         if (is_int($iKey))
                             $content .= $key ."[] = $iVal\n";

                         else
                             $content .= $key ."[$iKey] = $iVal\n";
                     }
                 }
             }
             else
             {
                 $content .= "$key = $val\n";
             }
         }
      }
   }
?>
